import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import About from '../views/About.vue'
import Deil from "../views/deil.vue"

import First from "../views/child/first.vue"
import Two from "../views/child/two.vue"
import Tree from "../views/child/tree.vue"
import Four from "../views/child/four.vue"
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:"/first",
    component: Home,
    children:[
      {
        path: '/first',
        name: 'First',
        component: First
      },
      {
        path: '/two',
        name: 'Two',
        component: Two
      },
      {
        path: '/tree',
        name: 'Tree',
        component: Tree
      },
      {
        path: '/four',
        name: 'Four',
        component: Four
      },
    ]
  },
  {
    path: '/deil/:id',
    name: 'Deil',
    component: Deil
  },
  {
    path: '/about',
    name: 'About',
    component: About
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
  const token=window.localStorage.getItem("token")
  if(to.path!=="/about")
  if(!token){
    next("/about")
  }else{
    next()
  }
  next()
})
export default router
